ResolveAliasFile
ResolveAliasFile Resolve an alias file
#include <Aliases.h> Finder Interface
OSErr ResolveAliasFile (theSpec, resolvedAliasChains, targetIsFolder,
wasAliased);
FSSpec *theSpec ; pointer to a file system specification record
Boolean resolvedAliasChains ; TRUE = resolve all aliases in a chain
Boolean * targetIsFolder ; TRUE = target is a folder
Boolean *wasAliased ; TRUE = target was aliased
ResolveAliasFile, like all other Alias Manager routines, accepts and
returns file specifications only in the form of file system specification records
defined by the FSSpec data type. The file system specification record
represents a simple and complete description of a file system object. It
contains a volume reference number, a parent directory ID, and a name. Use
the File Manager function MakeFSSpec to convert other forms of file
identification, such as full pathnames, into file system specifications.
You specify the file or directory you plan to open by passing a file system
specification record in the parameter theSpec. ResolveAliasFile returns the
name and location of the target file in theSpec.
ResolveAliasFile can follow a chain of aliases, up to a reasonable maximum
defined for the system, to the ultimate target. Set the resolveAliasChains
parameter to TRUE if you want ResolveAliasFile to resolve all aliases in a
chain, stopping only when it reaches the target file. Set it to FALSE if you want
to resolve only one alias file, even if the target is another alias file.
The parameters targetIsFolder and wasAliased are return parameters only.
ResolveAliasFile always initializes these parameters to FALSE. It sets
targetIsFolder to TRUE if the parameter theSpec points to a directory or a
volume. It sets wasAliased to TRUE if the file originally passed in the
parameter theSpec points to an alias file.
ResolveAliasFile first checks the catalog entry for the file or directory
specified in theSpec to determine whether it is an alias and whether it is a file
or a directory. If the object is not an alias, ResolveAliasFile leaves theSpec
un changed, sets the targetIsFolder parameter to TRUE for a directory or
volume and FALSE for a file, sets wasAliased to FALSE, and returns noErr. If
the object is an alias, ResolveAliasFile resolves it, places the target in the
parameter theSpec, and sets the wasAliased flag to TRUE.
When ResolveAliasFile finds the specified volume and parent directory but
fails to find the target file or directory in that location, ResolveAliasFile
returns a result code of fnfErr and fills in the parameter theSpec with a
complete file system specification record describing the target (that is, the
volume reference number, parent directory ID, and filename or folder name).
The file system specification record is valid, although the object it describes
does not exist. This information is intended as a “hint” that lets you explore
possible solutions to the resolution failure. You can, for example, use the file
system specification record to create a replacement for a missing file with the
File Manager function FSpCreate.
If ResolveAliasFile receives an error code while resolving an alias, it
leaves the input parameters as they are and exits, returning the error code. In
addition to any of these result codes, ResolveAliasFile can also return any
Resource Manager or File Manager errors.
Note: When opening a file without going through the Finder or the
Standard File Package, you call ResolveAliasFile immediately
before opening the file. In the following code example, the customized open
function, MyOpen, ensures that the file to be opened is the target file, and
then opens the data fork with the FSpOpenDF function.
Returns: an Error code. It will be one of the following:
nsvErr (-35) Volume not found
fnfErr (-43 Target not found, but volume and parent directory
found, and theSpec parameter contains a valid file
system specification record
dirNFErr (-120) Parent directory not found
The following is an example of using ResolveAliasFile:
Using the ResolveAliasFile function to open a file
// Assuming inclusion of
#include <Aliases.h>
OSErr MyOpen (FSSpec *theSpec, char perm, short * fRefNum)
{
OSErr myErr;
Boolean targetIsFolder,wasAliased;
*fRefNum = -1; // initialize fRefNum
myErr = ResolveAliasFile (theSpec, TRUE, & targetIsFolder,
&wasAliased);
if ( targetIsFolder)
myErr = paramErr; // cannot open a folder
else
if (myErr) // try to open it
myErr = FSpOpenDF(theSpec, perm, fRefNum);
return myErr;
}